get_trades(self, account_id, **params)
In [1]:
from datetime import datetime, timedelta
import pandas as pd
import oandapy
import configparser
config = configparser.ConfigParser()
config.read('../config/config_v1.ini')
account_id = config['oanda']['account_id']
api_key = config['oanda']['api_key']
oanda = oandapy.API(environment="practice",
access_token=api_key)
In [2]:
trade_expire = datetime.now() + timedelta(days=1)
trade_expire = trade_expire.isoformat("T") + "Z"
fx_list = ["EUR_USD", "USD_CHF", "GBP_USD"]
for oo in fx_list:
response = oanda.create_order(account_id,
instrument = oo,
units=1000,
side="buy",
type="market",
expiry=trade_expire)
In [3]:
response = oanda.get_trades(account_id)
pd.DataFrame((response['trades']))
Out[3]:
In [4]:
trade_id = response['trades'][0]['id']
In [5]:
response = oanda.get_trade(account_id,trade_id=trade_id)
print(response)
You can also obtain modify trade and close trade by calling on the following APIs:
modify_trade(self, account_id, trade_id, **params)
close_trade(self, account_id, trade_id, **params)
In [6]:
response = oanda.modify_trade(account_id,trade_id=trade_id, stopLoss=1.15)
print(response)
In [7]:
response = oanda.close_trade(account_id, instrument='EUR_USD',
trade_id=trade_id)
print(response)
In [8]:
response = oanda.get_trades(account_id)
pd.DataFrame(response['trades'])
Out[8]: